package com.meitianhui.convenitenbuy.module.home.presenter;

import com.google.gson.Gson;
import com.meitianhui.convenitenbuy.App;
import com.meitianhui.convenitenbuy.base.BaseResponse;
import com.meitianhui.convenitenbuy.config.InfoProvider;
import com.meitianhui.convenitenbuy.http.ResponseObserver;
import com.meitianhui.convenitenbuy.module.home.contract.FightGroupAddressContract;
import com.meitianhui.convenitenbuy.module.home.http.HomeApiDataSource;
import com.meitianhui.convenitenbuy.module.home.model.bean.FightGroupAddress;
import com.meitianhui.convenitenbuy.module.home.ui.activity.FightGroupAddressActivity;

import java.util.HashMap;
import java.util.Map;

public class FightGroupAddressPresenter implements FightGroupAddressContract.Presenter {

    private FightGroupAddressActivity mContext;
    private FightGroupAddressContract.View mView;

    public FightGroupAddressPresenter(FightGroupAddressContract.View view,
                                      FightGroupAddressActivity context) {
        this.mView = view;
        this.mContext = context;
    }

    @Override
    public void getFightGroupAddress(String pageIndex, String pageSize,
                                     String longitude, String latitude) {
        Map<String, String> maps = new HashMap<>();
        maps.put("page_no", pageIndex);
        maps.put("page_size", pageSize);
        String pageJson = new Gson().toJson(maps);

        Map<String, String> map = new HashMap<>();
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        String paramJson = new Gson().toJson(map);

        HomeApiDataSource.getInstance()
                .getFightGroupAddress(InfoProvider.getUserToken(App.getInstance()).getUser_token(),
                        "stores.consumer.nearbyHSPostListPageFind", pageJson, paramJson)
                .subscribe(new ResponseObserver<BaseResponse<FightGroupAddress>>(mContext, true) {
            @Override
            public void onSuccess(BaseResponse<FightGroupAddress> response) {
                mView.getFightGroupAddressSuccess(response.data);
            }
        });
    }

    @Override
    public void attachView(Object view) {
    }

    @Override
    public void detachView() {
    }

}
